package com.thh.shirodemo.controller;

import com.sun.org.apache.bcel.internal.classfile.Code;
import com.thh.shirodemo.bean.User;
import com.thh.shirodemo.util.PhoneCode;
import com.thh.shirodemo.util.PhoneCode;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shkstart
 * @create 2022-07-25-21:23
 */
@RestController
@RequiresPermissions("salary")
public class RedisCodeController {
    /**
     *生成验证码
     */
    @RequestMapping("/getCode")
    public String getCode(){
        //获取当前对象
        Subject subject = SecurityUtils.getSubject();
        User currentUser = (User)subject.getSession().getAttribute("currentUser");
        String msg = PhoneCode.verifyCode(String.valueOf(currentUser.getUserId()));
        return msg;
    }

    /**
     * 校验验证码
     */
    @RequestMapping(value = "checkCode")
    public String checkCode(@RequestParam(value = "codes") String code){
        //获取当前对象
        Subject subject = SecurityUtils.getSubject();
        User currentUser = (User)subject.getSession().getAttribute("currentUser");
        String msg = PhoneCode.checkRedisCode(String.valueOf(currentUser.getUserId()),code);
        return msg;
    }
}
